import {
  create,
  deleteById,
  listAllByPage,
  queryAllDicts,
  update,
} from '@/services/productionwasteApi';

export default {
  namespace: 'productionwaste',
  state: {
    data: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    /**
     * 分页获取数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllByPage({ payload }, { call, put }) {
      const response = yield call(listAllByPage, payload);
      yield put({
        type: 'cb4listAllByPage',
        payload: response,
      });
    },

    /**
     * 新增
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *create({ payload }, { call, put }) {
      const response = yield call(create, payload);
      return response;
    },

    /**
     * 更新
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *update({ payload }, { call, put }) {
      const response = yield call(update, payload);
      return response;
    },

    /**
     * 获取页面需要的所有的数据字典信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *queryAllDicts({ payload }, { call, put }) {
      const response = yield call(queryAllDicts, payload);
      return response;
    },

    /**
     * 删除
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *deleteById({ payload }, { call, put }) {
      const response = yield call(deleteById, payload);
      return response;
    },
  },

  reducers: {
    cb4listAllByPage(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
